﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NF_Tools
{
    public partial class BF_QueryTextBox : UserControl
    {
        public BF_QueryTextBox()
        {
            InitializeComponent();
            txtQuery.Width = 100;
            txtQuery.BorderStyle = BorderStyle.None;   
        }

        private Color _linecolor = Color.FromArgb(228, 228, 228);
        /// <summary>
        /// 线条颜色
        /// </summary>
        public Color LineColor
        {
            get
            {
                return this._linecolor;
            }
            set
            {
                this._linecolor = value;
                this.Invalidate();
            }
        }


        [Browsable(true), Category("自定义属性"), Description("Text")]
        public string QueryText
        {
            get { return txtQuery.Text; }
            set { txtQuery.Text = value; }
        }

        /// <summary>
        /// 重绘
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            using (Pen p = new Pen(this._linecolor, 2))
            {
                Rectangle rec = new Rectangle(0, 0, this.Height - 1, this.Height - 1);
                e.Graphics.DrawArc(p, rec, 90, 180);//绘制左半边弧形
                Rectangle rec1 = new Rectangle(this.Width - this.Height - 1, 0, this.Height - 1, this.Height - 1);
                e.Graphics.DrawArc(p, rec1, 270, 180);//绘制右半边弧形

                e.Graphics.DrawLine(p, new Point(this.Height / 2, 1), new Point(this.Width - this.Height / 2, 1));
                e.Graphics.DrawLine(p, new Point(this.Height / 2, this.Height - 1), new Point(this.Width - this.Height / 2, this.Height - 1));

            }
        }

        //定义委托
        public delegate void PicQuery(object sender, EventArgs e);
        //定义事件
        public event PicQuery Query;

        /// <summary>
        /// 查询的触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (Query != null)
                Query(sender, new EventArgs());//把按钮自身作为参数传递
        }

        /// <summary>
        /// 回车事件启动查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtQuery_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                pictureBox1_Click(null, null);
            }
        }

    }
}
